function readPlot(chapter) {
    return fetch('../plots/' + chapter + '.txt') // 确保路径正确
        .then(response => {
            if (!response.ok) {
                throw new Error('网络响应不正常');
            }
            return response.text();
        })
        .then(data => {
            console.log('获取到的数据:', data);
            return data;
        })
        .catch(error => {
            console.error('读取文件时出错:', error);
            return '读取文件时出错';
        });
}

async function displayPlot() {

    const plot = await readPlot(1); // 等待 readPlot 完成并返回数据
    //console.log('在 test 函数中获取到的数据:', plot);
    const lines = plot.split("\n");
    console.log(lines); // 调试
    if (plot !== '读取文件时出错') {
        document.getElementById('content').innerHTML = "";
        //lines = lines.split(" ");
        for (var i = 1; i < lines.length; i++) {
            document.getElementById("title").textContent = lines[0];
            var line = document.createElement("p");
            line.textContent = lines[i];
            if (lines[i][1] === "-") {
                line.classList.add("gradient")
                switch (lines[i][0]) {
                    case 'c':
                        line.classList.add("crazy-mita");
                        break;
                    case 'k':
                        line.classList.add("kind-mita");
                        break;
                    case 'h':
                        line.classList.add("hat-mita");
                        break;
                    case 'l':
                        line.classList.add("little-mita");
                        break;
                    case 'm':
                        line.classList.add("mini-mita");
                        break;
                    case 's':
                        line.classList.add("shorthair-mita");
                        break;
                    case 'g':
                        line.classList.add("ghost-mita");
                        break;
                    case 'e':
                        line.classList.add("sleep-mita");
                        break;
                    case 'd':
                        line.classList.add("d2-mita");
                        break;
                    case 'i':
                        line.classList.add("mila");
                        break;
                    case 'o':
                        line.classList.add("oldver-mita");
                        break;
                    case 'p':
                        line.classList.add("maleMC");
                        break;
                    case 'u':
                        line.classList.add("hurt-player");
                        break;
                    default:
                        break;
                }
                line.textContent = lines[i].slice(2);
            }else{
                line.classList.add("narrative");
            }

            document.getElementById('content').appendChild(line);
        }
        //document.getElementById('content').innerHTML = lines; // 设置 innerHTML
    } else {
        document.getElementById('content').innerHTML = plot; // 如果出错，直接显示错误信息
    }
}
//57Gz5aGU4p2k54ix5L2g